﻿using DAL;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace ShopBack.Web.Controllers
{
    [Authorize]
    public class ModuleController : Controller
    {
        // GET: Module
        public ActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 获取模块数据
        /// </summary>
        /// <returns></returns>
        public ActionResult GetModuleData()
        {
            List<Module> list = ModuleService.GetModelsMsg();
            return Json(new { code = 0, msg = "", data = list, count = list.Count }, JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 添加父级模块页面
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult Add()
        {
            return View();
        }
        /// <summary>
        /// 添加父级模块数据
        /// </summary>
        /// <param name="module"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult Add(Module module)
        {
            int a = ModuleService.GetAdd(module);
            if (a > 0)
            {
                return Json(new { Success = true, Message = "添加成功" });
            }
            else
            {
                return Json(new { Success = false, Message = "添加失败" });
            }
        }
        /// <summary>
        /// 删除模块
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Del(int id)
        {
            int a = ModuleService.GetDel(id);
            if (a > 0)
            {
                return Json(new { Success = true, Message = "删除成功" });
            }
            else
            {
                return Json(new { Success = false, Message = "删除失败" });
            }
        }
        /// <summary>
        /// 修改模块页面
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public ActionResult Update(int id)
        {
            Module module = ModuleService.GetSelect(id);
            return View(module);
        }
        /// <summary>
        /// 修改模块信息
        /// </summary>
        /// <param name="module"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult Update(Module module)
        {
            int a = ModuleService.GetUpdate(module);
            if (a > 0)
            {
                return Json(new { Success = true, Message = "修改成功" });
            }
            else
            {
                return Json(new { Success = false, Message = "修改失败" });
            }
        }
        /// <summary>
        /// 添加子模块页面
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public ActionResult Add1(int id)
        {
            Module module = ModuleService.GetSelect(id);
            return View(module);
        }
        /// <summary>
        /// 添加模块数据
        /// </summary>
        /// <param name="module"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult Add1(Module module)
        {
            int a = ModuleService.GetAdd(module);
            if (a > 0)
            {
                return Json(new { Success = true, Message = "添加成功" });
            }
            else
            {
                return Json(new { Success = false, Message = "添加失败" });
            }
        }
    }
}